<template>
    <div>
      <!-- 面包屑 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- 卡片试图 -->
      <el-card>
        <!-- 搜索区域 -->
        <el-row>
          <el-col :span="8">
            <el-input placeholder="请输入内容" class="input-with-select">
              <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input>
          </el-col>
        </el-row>
        <!-- 表格区域 -->
        <el-table :data="orders" border stripe>
          <el-table-column label="#" type="index"></el-table-column>
          <el-table-column label="订单编号" prop="order_number"></el-table-column>
          <el-table-column width="130" label="订单价格" prop="order_price"></el-table-column>
          <el-table-column width="130" label="是否付款">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.pay_status==='0'" type="danger">未付款</el-tag>
              <el-tag v-else type="success">已付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column width="130" label="是否发货" prop="is_send"></el-table-column>
          <el-table-column width="180" label="下单时间">
            <template slot-scope="scope">
              {{ scope.row.create_time | formatDate }}
            </template>
          </el-table-column>
          <el-table-column width="130" label="操作" prop="order_number">
            <template>
              <el-button @click="editAddressDialogVisible=true" size="mini" type="primary" icon="el-icon-edit"></el-button>
              <el-button @click="showProgress()" size="mini" type="success" icon="el-icon-location"></el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryData.pagenum"
          :page-sizes="[5, 10, 20, 40]"
          :page-size="queryData.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-card>
      <!-- 修改地址 -->
      <el-dialog
        title="修改地址"
        :visible.sync="editAddressDialogVisible"
        width="50%">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="省市区/县" prop="infoAddress">
            <el-cascader
             :options="cityData"
             v-model="ruleForm.address"
            >
            </el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="infoAddress">
            <el-input v-model="ruleForm.infoAddress"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editAddressDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="editAddrerss()">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 物流进度对话框 -->
      <el-dialog 
      :visible.sync="progressDialogVisible"
      title="查看物流进度">
        <el-timeline :reverse="true">
          <el-timeline-item
            v-for="(item, index) in expressProgress"
            :key="index"
            :timestamp="item.ftime">
            {{item.context}}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data() {
    return {
      queryData: {
        // 搜索字段
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orders: [],
      total: 0,
      editAddressDialogVisible: false,
      ruleForm: {
        address: [],
        infoAddress: ''
      },
      rules: {
        infoAddress: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      cityData,
      progressDialogVisible: false,
      expressProgress: []
    }
  },

  created() {
    this.getOrdersList()
  },

  methods: {
    // 获取订单列表
    async getOrdersList () {
      const { data: res } = await this.$axios.get('orders',{
        params: this.queryData
      })
      if(res.meta.status !== 200) return this.$message.error('获取数据失败')
      this.orders = res.data.goods
      this.total = res.data.total
    }, 
    // 每页条数发生变化触发
    handleSizeChange (val) {
      this.queryData.pagesize = val
      this.getOrdersList()
    },
    // 页码发生变化
    handleCurrentChange (val) {
      this.queryData.pagenum = val
      this.getOrdersList()
    },
    // 点击确定编辑
    editAddrerss () {
      console.log(this.ruleForm)
    },
    // 显示物流进度
    async showProgress () {
      this.progressDialogVisible = true
      const {data: res} = await this.$axios.get('/kuaidi/1106975712662')
      this.expressProgress = res.data
    }
  }
};
</script>

<style scoped lang='less'>

</style>
